import os
import logging
from time import sleep
from selenium import webdriver
from selenium.webdriver.support.select import Select
from selenium.webdriver.support.ui import WebDriverWait


driver = webdriver.Chrome()
driver.implicitly_wait(5)

# 获取html绝对路径
file_path = os.path.join('file:///', os.getcwd(), "selenium.html")
logging.info(file_path)

# 打开html文件
driver.get(file_path)

#最大化窗口
driver.maximize_window()

driver.find_element_by_xpath('//*[@id="signup"]/form/input[1]').send_keys('rabbit')
driver.find_element_by_xpath('//*[@id="signup"]/form/input[2]').send_keys('love')
opt=driver.find_element_by_xpath('//*[@id="signup"]/form/select')
Select(opt).select_by_visible_text('深圳')
driver.find_element_by_xpath('//*[@id="signup"]/form/input[3]').click()

# 显式等待,超时时间10秒，每秒查找一次
success_elem = WebDriverWait(driver, 10, 1).until(
    lambda x: x.find_element_by_xpath('//*[@id="signup"]/p').text == "注册成功")
sleep(2)

driver.close()

driver.quit()



